package com.fr.report.script.function;

import com.fr.report.script.Calculator;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import java.util.HashMap;
import java.util.Map;

public class SEQ extends NormalFunction
{
  private static final Object SEQMAP = new Object();
  private static final Object NULL = new Object();

  public Object run(Object[] paramArrayOfObject)
  {
    Object localObject3;
    Integer localInteger;
    Object localObject1 = null;
    if (paramArrayOfObject.length > 0)
      localObject1 = paramArrayOfObject[0];
    if (localObject1 == null)
      localObject1 = NULL;
    Calculator localCalculator = getCalculator();
    Object localObject2 = localCalculator.getAttribute(SEQMAP);
    if (localObject2 instanceof Map)
    {
      localObject3 = (Map)localObject2;
    }
    else
    {
      localObject3 = new HashMap();
      localCalculator.setAttribute(SEQMAP, localObject3);
    }
    synchronized (SEQMAP)
    {
      Object localObject5 = ((Map)localObject3).get(localObject1);
      if (localObject5 instanceof Integer)
        localInteger = new Integer(((Integer)localObject5).intValue() + 1);
      else
        localInteger = new Integer(1);
      ((Map)localObject3).put(localObject1, localInteger);
    }
    return localInteger;
  }

  public Function.Type getType()
  {
    return Function.OTHER;
  }

  public String getCN()
  {
    return "SEQ(): 返回数值，在整个报表执行过程中，返回该函数被第几次执行了。\n示例:\nSEQ()在第一次执行时，结果为1。\nSEQ()在第二次执行时，结果为2。";
  }

  public String getEN()
  {
    return "SEQ(): Returns a value of number which means the times this function is used during the report execution.\nExample:\nSEQ() returns 1 when used first time.\nSEQ() returns 2 when used second time.";
  }
}